package com.yoomiito.app.ui.order.list


import android.graphics.Typeface
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import android.text.Spannable
import android.text.SpannableString
import android.text.style.RelativeSizeSpan
import android.text.style.StyleSpan
import android.view.View
import android.widget.TextView

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.yoomiito.app.R
import com.yoomiito.app.model.bean.OrderInfo
import com.yoomiito.app.utils.AllCode
import com.yoomiito.app.utils.DensityUtil
import com.yoomiito.app.widget.SpacingDecoration

class BaoPinOrderAdapter(data: List<OrderInfo>?) : BaseQuickAdapter<OrderInfo, BaseViewHolder>(R.layout.item_baopin_order, data) {
    var onParentChildClickListener:(BaseQuickAdapter<*, *>,View,Int,Int)->Unit = { _, _, _, _-> }
    override fun convert(helper: BaseViewHolder, item: OrderInfo) {
        helper.setText(R.id.order_id, "订单：" + item.order_id)
        if (item.order_detail != null && item.order_detail.size == 1) {
            helper.setText(R.id.order_status, AllCode.getOrderStatus(item.status))
        } else {
            helper.setText(R.id.order_status, "")
        }
        val price = "共${item.num}件 合计¥${item.price}"
        val startP = price.indexOf("¥")
        val endP = price.indexOf(".")
        val spanText = SpannableString(price)
        spanText.setSpan(RelativeSizeSpan(0.8f), 0, startP, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
        spanText.setSpan(RelativeSizeSpan(0.8f), endP, price.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
        helper.setText(R.id.order_size_price,spanText)

        val rcy = helper.getView<androidx.recyclerview.widget.RecyclerView>(R.id.rcy)
        rcy.layoutManager = androidx.recyclerview.widget.LinearLayoutManager(rcy.context)
        if (rcy.itemDecorationCount > 0) {
            val itemDecoration = rcy.getItemDecorationAt(0)
            if (itemDecoration == null) {
                rcy.addItemDecoration(SpacingDecoration(0, DensityUtil.dp2px(10f), false))
            }
        } else {
            rcy.addItemDecoration(SpacingDecoration(0, DensityUtil.dp2px(10f), false))
        }
        val goodsAdapter = BaoPinOrderGoodsAdapter(item.order_detail)
        goodsAdapter.setOnItemClickListener { adapter, view, position ->
            onParentChildClickListener(adapter, view, position, helper.layoutPosition)
        }
        rcy.adapter = goodsAdapter
    }
}
